package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.entity.iotModule.PersonnelPositioning;
import com.site.wisdom_construction.entity.iotModule.PersonnelPositioningRecord;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.service.iotModule.PersonnelPositioningRecordService;
import com.site.wisdom_construction.service.iotModule.PersonnelPositioningService;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/10
 * @Description
 */
@Api(tags = "人员定位接口")
@RestController
@RequestMapping("PersonnelPositioning")
@CrossOrigin
public class PersonnelPositioningController {
    @Autowired
    private PersonnelPositioningService personnelPositioningService;

    @Autowired
    private PersonnelPositioningRecordService personnelPositioningRecordService;

    @ApiOperation(value = "增加人员定位信息", notes = "测试数据:")
    @PostMapping("/insertPersonnelPositioning")
    @NoToken
    public String insertPersonnelPositioning(@RequestBody Map map) {
        String e = (String) map.get("equipmentId");
        String equipmentId = e.replaceAll("\u0000","");
        map.put("equipmentId",equipmentId);

        String ea = (String) map.get("tagId");
        String tagId = ea.replaceAll("\u0000","");
        map.put("tagId",tagId);
        map.put("projectId",1);
        PersonnelPositioning personnelPositioning = personnelPositioningService.findPersonnelPositioningByTagId(map);
        personnelPositioningRecordService.insertPersonnelPositioningRecord(map);
        if (personnelPositioning == null) {
            personnelPositioningService.insertPersonnelPositioning(map);
            return "增加!";
        }else {
            personnelPositioningService.updatePersonnelPositioning(map);
            return "修改!";
        }
    }


    @ApiOperation(value = "统计实时人数", notes = "测试数据:")
    @PostMapping("/countALL")
    public int countALL(@RequestBody Map map) {
        personnelPositioningService.deletePersonnelPositioningByUpdateTime(map);
        return personnelPositioningService.countALL(map);
    }

    @ApiOperation(value = "根据设备id查询标签id信息", notes = "")
    @PostMapping("/findPersonnelPositioningByEquipmentId")
    public OneDataResult findPersonnelPositioningByEquipmentId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        personnelPositioningService.deletePersonnelPositioningByUpdateTime(map);
        oneDataResult.setData(personnelPositioningService.findPersonnelPositioningByEquipmentId(map));
        return oneDataResult;
    }
}
